# ------------------------------------------------------------------------------
#
# Copyright (c) 2011 - The OWE Team
#
# This file is part of OWE.
#
# OWE is a free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; version
# version 2.1 of the License.
#
# OWE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with OWE. If not, see <http://www.gnu.org/licenses/>.
#
# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# Qt libraries
# ------------------------------------------------------------------------------
if(ENABLE_QT)
    set(OWE_PLATFORM_QT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/platform/qt)
    include(${OWE_PLATFORM_QT_DIR}/qt.cmake REQUIRED)
endif()

# ------------------------------------------------------------------------------
# GTK+ libraries
# ------------------------------------------------------------------------------
if(ENABLE_GTK)
    set(OWE_PLATFORM_GTK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/platform/gtk)
    include(${OWE_PLATFORM_GTK_DIR}/gtk.cmake REQUIRED)
endif()

# ------------------------------------------------------------------------------
# Common implementation
#
# PLATFORM_SOURCE_FILES and PLATFORM_LIBRARIES variables should be defined by
# the platform include enabled above. OWE it's only complete if linked with some
# toolkit to resolve all missing symbols.
# ------------------------------------------------------------------------------

set(OWE_SOURCE_FILES
    ${OWE_CONFIGURATION_DIR}/authorelement.cpp
    ${OWE_CONFIGURATION_DIR}/configurationdocument.cpp
    ${OWE_CONFIGURATION_DIR}/contentelement.cpp
    ${OWE_CONFIGURATION_DIR}/descriptionelement.cpp
    ${OWE_CONFIGURATION_DIR}/element.cpp
    ${OWE_CONFIGURATION_DIR}/featureelement.cpp
    ${OWE_CONFIGURATION_DIR}/iconelement.cpp
    ${OWE_CONFIGURATION_DIR}/licenseelement.cpp
    ${OWE_CONFIGURATION_DIR}/nameelement.cpp
    ${OWE_CONFIGURATION_DIR}/paramelement.cpp
    ${OWE_CONFIGURATION_DIR}/preferenceelement.cpp
    ${OWE_CONFIGURATION_DIR}/textelement.cpp
    ${OWE_CONFIGURATION_DIR}/widgetelement.cpp
    ${OWE_INTERFACES_DIR}/widget/widgetinterface.cpp
    ${OWE_PACKAGING_DIR}/widgetpackage.cpp
)

set(OWE_PUBLIC_HEADERS
    ${OWE_CONFIGURATION_DIR}/authorelement.h
    ${OWE_CONFIGURATION_DIR}/configparser.h
    ${OWE_CONFIGURATION_DIR}/configurationdocument.h
    ${OWE_CONFIGURATION_DIR}/contentelement.h
    ${OWE_CONFIGURATION_DIR}/descriptionelement.h
    ${OWE_CONFIGURATION_DIR}/element.h
    ${OWE_CONFIGURATION_DIR}/featureelement.h
    ${OWE_CONFIGURATION_DIR}/iconelement.h
    ${OWE_CONFIGURATION_DIR}/licenseelement.h
    ${OWE_CONFIGURATION_DIR}/nameelement.h
    ${OWE_CONFIGURATION_DIR}/node.h
    ${OWE_CONFIGURATION_DIR}/paramelement.h
    ${OWE_CONFIGURATION_DIR}/preferenceelement.h
    ${OWE_CONFIGURATION_DIR}/textelement.h
    ${OWE_CONFIGURATION_DIR}/widgetelement.h
    ${OWE_INTERFACES_DIR}/widget/widgetinterface.h
    ${OWE_PACKAGING_DIR}/widgetpackage.h
    ${OWE_UTILS_DIR}/global.h
    ${OWE_UTILS_DIR}/platform.h
    ${OWE_UTILS_DIR}/ustring.h
)

add_library(owe SHARED ${OWE_SOURCE_FILES} ${PLATFORM_SOURCE_FILES})
target_link_libraries(owe ${PLATFORM_LIBRARIES})

# ------------------------------------------------------------------------------
# Copy headers to include dir
# ------------------------------------------------------------------------------
add_custom_target(copy_headers)
add_dependencies(owe copy_headers)

add_custom_command(TARGET copy_headers POST_BUILD
    COMMAND ${CMAKE_COMMAND}
    ARGS -E make_directory ${CMAKE_BINARY_DIR}/include/owe
)

foreach(HEADER ${OWE_PUBLIC_HEADERS})
    add_custom_command(TARGET copy_headers POST_BUILD
        COMMAND ${CMAKE_COMMAND}
        ARGS -E copy_if_different ${HEADER} ${CMAKE_BINARY_DIR}/include/owe
    )
endforeach(HEADER)
